<template>
	<view>
		<uni-search-bar cancelButton cancelText="全部" @cancel="unsearch" placeholder="请输入姓名/工号查找" @confirm="searchRemote" @input="searchLocal" class="sb"/>
		<view style="padding-top: 100rpx;">
			<uni-list v-if="searched==false">
				<uni-list-item v-for="(maintainer, idx) in maintainers" :key='idx' 
				:title="`${maintainer.name} 当前${maintainer.count}单`" clickable @click="choose($event, idx)"></uni-list-item>
			</uni-list>
			<uni-list v-else>
				<uni-list-item :key="idx" v-for="(v, idx) in visibles" 
				:title="`${maintainers[v].name} 当前${maintainers[v].count}单`" clickable @click="choose($event, idx)"></uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		onLoad(opts) {
			uni.request({
				header:{
					Authorization: 'Bearer ' + app.globalData.token,
				},
				url: app.globalData.adurl + 'workOrder/getMaintenanceStaffList',
				method: 'GET',
				data: {},
				success: res => {
					const {data} = res
					if(data.code==200){
						const {d} = data
						this.maintainers.push(...d)
					}else if(data.code==500){
						uni.showToast({
							icon:'none',
							title: data.message,
						});
					}
				},
				fail: (err) => {console.error(err)},
				complete: () => {}
			});
		},
		data() {
			return {
				maintainers:[
					
				],
				searched: false, 
				visibles:[]
			}
		},
		methods: {
			unsearch(){
				this.searched=false
				this.visibles=[]
			},
			searchLocal(evt){
				for (let mi in this.maintainers) {
					const m = this.maintainers[mi]
					if(m.name.indexOf(evt.value)>-1){
						this.visibles.push(mi)
					}
				}
				this.searched=true
			},
			
			choose(evt, idx){
				// 出发选中人员
				app.globalData.returns.maintainer = this.maintainers[idx]
				uni.navigateBack()
			}
		}
	}
</script>

<style>
	page{
		padding: 0;
	}
	
	.sb{
		width: 750rpx; 
		z-index: 999;
		position: fixed;
	}
</style>
